﻿//产品收货(收货确认) 确认
var columns =
            [
                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '发货单号', name: 'DeliveryNo', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '发货人时间', name: 'DeliveryDate', mintWidth: 180, width: 180, type: "selfDate" },
                {display: '发货仓库', name: 'StorehouseName', mintWidth: 80, width: 140 },
                { display: '发货人名称', name: 'DeliveryorName', mintWidth: 80, width: 120 },
                { display: '送货人名称', name: 'SenderName', mintWidth: 80, width: 120 },
                { display: '收货单位名称', name: 'DeliveryName', mintWidth: 80, width: 120 },
                { display: 'AffirmState', name: 'AffirmState', type: 'text', hide: 1 },
                { display: '确认人', name: 'AffirmorName', mintWidth: 80, width: 120 },
                { display: '确认时间', name: 'AffirmDate', mintWidth: 180, width: 180, type: "selfDate" },
                { display: '确认状态', name: 'AffirmStateName', mintWidth: 100, width: 140 },
             //   { display: '是否结算', name: 'SettleState', mintWidth: 100, width: 140 },
             // { display: '删除状态', name: 'DeleteState', mintWidth: 80, width: 140 },
                { display: '备注', name: 'Remarks', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
    initDataControls();

    window.setTimeout(execLoops, 30000); //隔30秒执行
});

function initligerGrid() {
    manager = null;
    manager = $("#ProductDeliveryGrid").ligerGrid({
        columns: columns,
        title: '产品发货管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [{ text: '收货确认', click: audioOperation, icon: 'modify' },
                                    { line: true },
                                      { text: '打印', click: printOperation, img: '../Content/images/print.png' },
                                    { line: true },
                                    { text: '查看', click: dialogView, img: '../Content/images/Search.png'}]
        },
        parms: { orgCode: $("#HidOrgCode").val(), selectType: "confirm", isConfirm: $("#cbConfirm").val(), billNo: $("#billNo").val(), auditName: $("#auditName").val(), fhName: $("#fhName").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val() },
        url: "../ProductDelivery/GetJsonOfDatas?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) {viewDetail(data.Id); }
    });
}
//确认
function audioOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要确认的行!'); return; }
    var billId = row["Id"].toString();
    $.ligerDialog.open({ url: "../ProductDelivery/Detail?id="  + billId + "&orgCode=" + $("#HidOrgCode").val() + "&isConfirm=true", height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}


//function audioOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) {
//        $.ligerDialog.success('请选择要确认的行!'); return;
//    }
//    $.ligerDialog.confirm('入库记录已自动生成，确认并提交？', function (yes) {
//        if (yes) {
//            $.get("../ProductDelivery/Audit?orgCode="+ $("#HidOrgCode").val()+"&billId=" + row.Id + "&rand=" + Math.random(), {}, function (data) {
//                if (data != undefined && data == "9") {
//                    $.ligerDialog.success('收货确认成功!');
//                    initligerGrid();
//                }
//            });
//        }
//    });
//}

function dialogView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    $.ligerDialog.open({ url: "../ProductDelivery/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
function viewDetail(billId) {
    $.ligerDialog.open({ url: "../ProductDelivery/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(),isResize: true, isHidden: false });
}
//print
function printOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要打印的行!'); return;
    }
    if (row["AffirmState"].toString() != "1") { $.ligerDialog.success('单据未确认，不能打印!'); return; }
    window.showModalDialog("../ProductDelivery/Print?billId=" + row["Id"].toString(), window, "scroll:yes;dialogWidth=800;dialogHeight=600");
}

//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}



//每隔一段时间执行一次
function execLoops() {
    initligerGrid();
    window.setTimeout(execLoops, 10000); //每隔10S执行
}


